﻿using Models;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class DefaultManager
    {
        public static List<dynamic> GetMicroBlogs()
        {

            using (MicroBlogEntities db = new MicroBlogEntities())
            {
                var sql = from u in db.Users
                          from m in db.MicroBlog
                          where m.U_ID == u.U_ID
                          select new
                          {
                              m.M_Content,
                              m.M_FrowardingTimes,
                              m.M_DataTime,
                              u.U_Nick,
                              u.UserInfo_Image,
                              m.M_ID
                          };
                List<dynamic> list = new List<dynamic>();
                foreach (var item in sql.ToList())
                {
                    dynamic d = new ExpandoObject();
                    d.M_Content = item.M_Content;
                    d.M_FrowardingTimes = item.M_FrowardingTimes;
                    d.M_DataTime = item.M_DataTime;
                    d.U_Nick = item.U_Nick;
                    d.UserInfo_Image = item.UserInfo_Image;
                    d.M_ID = item.M_ID;
                    list.Add(d);
                }
                return list;


            }
        }
    }
}
